<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@include file="/WEB-INF/webpage/common/taglibs.jspf"%>
<!DOCTYPE html>
<html>
<head>
  <title><spring:message code="sys.user.title" /></title>
  <meta name="decorator" content="list"/>
  <html:component name="bootstrap-treeview"/>
  <html:css  name="iCheck,Validform,jquery-ztree,easy-ui"/>
  <html:js  name="iCheck,Validform,jquery-ztree,easy-ui,public-js"/>
  <style type="text/css">.row{margin:0;}</style>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <script type="text/javascript" src="${staticPath}/common/js/window.js"></script>
  <script type="text/javascript" src="${staticPath}/common/js/ztree.js"></script>
</head>
<body title="<spring:message code="sys.user.title" />">
<div class="easyui-layout" fit="true" id="cc" style="width:100%;">
	<div data-options="region:'west',split:true"  title="组织机构" style="width:20%;">
		 <div class="zTreeDemoBackground left">
			<ul id="treeObj" class="ztree"></ul>
		</div>
	</div>
	<div data-options="region:'center'" title="用户列表">
		 <div class="content-padding">
		<grid:grid id="userGridId" url="${adminPath}/sys/user/ajaxListUserByOrg" gridSetting="{beforeRequest:onloadFun,gridComplete:onloadFun}"
			dbUrl="${adminPath}/sys/user/{id}"  >
			<grid:column label="sys.common.key" hidden="true"   name="id" width="100"/>
			<grid:column label="sys.common.opt"  name="opt" formatter="button" width="40"/>
			<grid:button title="sys.user.org"  groupname="opt" function="rowDialogDetailRefresh" outclass="btn-info"  innerclass="fa-sitemap" url="${adminPath}/sys/user/configOrg?gid=\"+row.id+\"" />
			<%-- <grid:button groupname="opt" function="delete" url="${adminPath}/sys/user/{id}/deleteUser" /> --%>
			<grid:query name="orgId"  queryMode="hidden" />
		    <grid:column label="sys.user.realname"  name="realname"  query="true"  condition="like" width="60" />
		    <grid:column label="sys.user.username"  name="username"  query="true" condition="like"  width="60" />
		    <grid:column label="sys.user.belonged.org"  name="belongedOrg"/>
		    <grid:column label="sys.user.organization.name"  name="orgName"/>
		    <grid:column label="sys.user.email"  name="email"  width="60"/>
		    <grid:column label="sys.user.phone"  name="phone"  query="true"  condition="like"  width="60"/>
			<grid:toolbar title="sys.user.createuser" function="create" btnclass="btn-fa-plus" icon="fa-user-plus"   url="${adminPath}/sys/user/createUser"/>
		 	<grid:toolbar title="sys.user.updateuser" function="update" icon="fa-user"  url="${adminPath}/sys/user/{id}/updateUser"/>
			<grid:toolbar title="sys.user.modifypwd" icon="fa-unlock-alt"  function="updateDialog" url="${adminPath}/sys/user/{id}/changePassword"  />
			<grid:toolbar title="重置密码" icon="fa-unlock-alt" function="defpassword"/>
			<grid:toolbar function="delete"  url="${adminPath}/sys/user/batch/deleteUser"/>
			<grid:toolbar  function="search"/>
			<grid:toolbar  function="reset"/>
		</grid:grid>
		</div>
	</div>
</div>
<script type="text/javascript">
	var treeObj;
	
	/**
	 * @description 设置加载配置.<br>
	 * @date 2018/3/29.<br>
	 * @author zcg .<br>
	 */
	var setting = {
			callback: {
				onClick: onClick
			}
		};
	
	/**
	 * @description 初始化加载js.<br>
	 * @date 2018/3/29.<br>
	 * @author zcg .<br>
	 */
	$(function(){
		var url = '${adminPath}/sys/organization/findOrgTree';
		treeObj = $.ztree('treeObj',url,setting);
	});
	
	function onClick(event, treeId, treeNode, clickFlag) {
		 //$("input[name='orgId']").val(treeNode.id);
	     search('userGridIdGrid',{nodeId:treeNode.id});
	}
	

	var gridId = "userGridIdGrid";
	function defpassword() {
	    var row = getSelectRows(gridId, false, true);
	    if (!row) {
	        return;
	    }
	    var username = row.username;
	    var url = "${adminPath}/sys/user/defchangePassword?userId=" + row.id;
	    layer.confirm("您确定要重置【" + username + "】的密码吗?请谨慎操作！", {
	        title: "提示",
	        icon: 3,
	        btn: ['确定', '取消'] //按钮
	    }, function () {
	        //确定
	        $.ajax({
	            url: url,
	            type: 'post',
	            data: {
	                id: row.id
	            },
	            success: function (d) {
	                var msg = d.msg;
	                layer.msg(msg, {icon: 3, shade: 0.3, time: 1000});
	            },
	            error:function (errorData) {
	                console.log(errorData);
	                layer.msg("重置失败", {icon: 3, shade: 0.3, time: 1000});
	            }
	        });
	    }, function () {
	        //取消
	    });
	} 

</script>
</body>
</html>